/**
 * 
 */
package com.tx.main.juhe;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.boot.jdbc.DataSourceBuilder;

import com.tx.core.ddlutil.builder.DDLBuilder;
import com.tx.core.ddlutil.builder.alter.AlterTableDDLBuilder;
import com.tx.core.ddlutil.builder.create.CreateTableDDLBuilder;
import com.tx.core.ddlutil.dialect.impl.MySQLDDLDialect;
import com.tx.core.ddlutil.executor.impl.MysqlTableDDLExecutor;
import com.tx.core.ddlutil.helper.JPAEntityDDLHelper;
import com.tx.core.ddlutil.model.TableColumnDef;
import com.tx.core.ddlutil.model.TableDef;
import com.tx.main.juhe.model.JuheVinParseResult;
import com.tx.model.DDLTestDemo;

/**
 * 
 */
public class JuheVINParseResultDDLHelper {

	public static void main(String[] args) {
		DataSource ds = DataSourceBuilder.create()
                .driverClassName("com.mysql.cj.jdbc.Driver")
                .url("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull")
                .username("root")
                .password("root")
                .build();
		MysqlTableDDLExecutor ddlExecutor = new MysqlTableDDLExecutor(ds);
        ddlExecutor.afterPropertiesSet();
        
        //解析对象
        TableDef tableDef = JPAEntityDDLHelper.analyzeToTableDefDetail(
                JuheVinParseResult.class,
                MySQLDDLDialect.INSTANCE);
        DDLBuilder ddlBuilder = null;
        if (!ddlExecutor.exists(tableDef.getName())) {
        	ddlBuilder = ddlExecutor
                    .generateCreateTableDDLBuilder(tableDef);
        	//创建表
        	ddlExecutor.create((CreateTableDDLBuilder)ddlBuilder);
        }else {
        	//更新表
        	ddlBuilder = ddlExecutor
                    .generateAlterTableDDLBuilder(tableDef);
        	ddlExecutor.alter((AlterTableDDLBuilder)ddlBuilder);
        }
        //ddlExecutor.create(createBuilder);
	}
}
